//
//  HNSH_XJDRCell.m
//  HNSH_SingleProject
//
//  Created by 李宇廷 on 2023/5/30.
//

#import "HNSH_XJDRCell.h"

@interface HNSH_XJDRCell ()

/* bgView */
@property (nonatomic, strong) UIView *bgView;
/* levelIcon */
@property (nonatomic, strong) UIImageView *levelIcon;
/* levelNameLabel */
@property (nonatomic, strong) UILabel *levelNameLabel;
/* lszzLabel */
@property (nonatomic, strong) UILabel *lszzLabel;
/* lszzIcon */
@property (nonatomic, strong) UIImageView *lszzIcon;

@end

@implementation HNSH_XJDRCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.backgroundColor = [UIColor whiteColor];
        [self configView];
    }
    return self;
}

- (void)setModel:(HNSH_XJDRItemModel *)model {
    _model = model;
    [self.levelIcon sd_setImageWithURL:[NSURL URLWithString:model.icon]];
    self.levelNameLabel.text = model.name;
    self.lszzLabel.text = [NSString stringWithFormat:@"%@%@",model.amount,model.amount_desc];
}

- (void)configView {
    [self.contentView addSubview:self.bgView];
    [self.bgView addSubview:self.levelIcon];
    [self.bgView addSubview:self.levelNameLabel];
    
    [self.bgView addSubview:self.lszzLabel];
    [self.bgView addSubview:self.lszzIcon];
    
    [self.lszzLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-16);
        make.centerY.equalTo(self.bgView.mas_centerY);
        make.height.mas_equalTo(20);
    }];
    [self.lszzIcon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.lszzLabel.mas_left).offset(-4);
        make.centerY.equalTo(self.bgView.mas_centerY);
        make.height.width.mas_equalTo(16);
    }];
}

#pragma mark lazy
- (UIView *)bgView {
    if (!_bgView) {
        _bgView = [[UIView alloc]initWithFrame:CGRectMake(16, 0, kScreenWidth-32, 52)];
        _bgView.backgroundColor = [UIColor colorWithHexString:@"#F8F8F8"];
        _bgView.layer.cornerRadius = 8.0f;
        _bgView.layer.masksToBounds = YES;
    }
    return _bgView;
}

- (UIImageView *)levelIcon {
    if (!_levelIcon) {
        _levelIcon = [[UIImageView alloc]initWithFrame:CGRectMake(16, 16, 20, 20)];
        _levelIcon.image = [UIImage imageNamed:@"xjdr_level_icon"];
    }
    return _levelIcon;
}

- (UILabel *)levelNameLabel {
    if (!_levelNameLabel) {
        _levelNameLabel = [[UILabel alloc]initWithFrame:CGRectMake(44, 16, 200, 20)];
        _levelNameLabel.text = @"一星达人";
        _levelNameLabel.textColor = [UIColor appBlackLabelColor];
        _levelNameLabel.font = [UIFont boldSystemFontOfSize:14];
    }
    return _levelNameLabel;
}

- (UIImageView *)lszzIcon {
    if (!_lszzIcon) {
        _lszzIcon = [[UIImageView alloc]init];
        _lszzIcon.image = [UIImage imageNamed:@"xjdr_lszz_icon"];
    }
    return _lszzIcon;
}

- (UILabel *)lszzLabel {
    if (!_lszzLabel) {
        _lszzLabel = [[UILabel alloc]init];
        _lszzLabel.text = @"";
        _lszzLabel.textColor = [UIColor colorWithHexString:@"#50AC2D"];
        _lszzLabel.font = [UIFont boldSystemFontOfSize:14];
    }
    return _lszzLabel;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
